$(function(){
   new Upload({
		elem: 'add-img-logo',
		url: '/Api/Upload/ajax_upload_file',
		name: 'Filedata',
		formId: 'upload-form-1',
		inputId: 'upload-1',
		accept: 'image/jpg, image/jpeg,image/png',
		success: function(json) {
						var str = '';
						if(json.code==1){
								str =  '<div class="list">'+
													'<img src="'+ json.url +'" alt="">'+
													'<div class="operate">'+
															'<i class="iconfont preview-img">&#xe615;</i>'+
															'<i class="iconfont delete-img">&#xe65f;</i>'+
													'</div>'+
													'<div class="musk"></div>'+
											'</div><input type="hidden" name="logo" value="'+ json.url +'"/>';
											
							$('.add-img-logo').before(str);
							if($('.hw-img-logo .list').length>=1){
								$('.add-img-logo').hide()
							}
						}
		},
		error: function() {
						
		}
	});
	new Upload({
		elem: 'add-img-banner',
		url: '/Api/Upload/ajax_upload_file',
		name: 'Filedata',
		formId: 'upload-form-1',
		inputId: 'upload-1',
		accept: 'image/jpg, image/jpeg,image/png',
		success: function(json) {
						var str = '';
						if(json.code==1){
								str =  '<div class="list">'+
													'<img src="'+ json.url +'" alt="">'+
													'<div class="operate">'+
															'<i class="iconfont preview-img">&#xe615;</i>'+
															'<i class="iconfont delete-img">&#xe65f;</i>'+
													'</div>'+
													'<div class="musk"></div>'+
											'</div><input type="hidden" name="banner" value="'+ json.url +'"/>';
											
											$('.add-img-banner').before(str);
							if($('.hw-img-banner .list').length>=1){
								$('.add-img-banner').hide()
							}
						}
		},
		error: function() {
						
		}
	});
	new Upload({
		elem: 'add-img-img',
		url: '/Api/Upload/ajax_upload_file',
		name: 'Filedata',
		formId: 'upload-form-1',
		inputId: 'upload-1',
		accept: 'image/jpg, image/jpeg,image/png',
		success: function(json) {
						var str = '';
						if(json.code==1){
								str =  '<div class="list">'+
													'<img src="'+ json.url +'" alt="">'+
													'<div class="operate">'+
															'<i class="iconfont preview-img">&#xe615;</i>'+
															'<i class="iconfont delete-img">&#xe65f;</i>'+
													'</div>'+
													'<div class="musk"></div>'+
											'</div><input type="hidden" name="img[]" value="'+ json.url +'"/>';
											
											$('.add-img-img').before(str);
							if($('.hw-img-img .list').length>=15){
								$('.add-img-img').hide()
							}
						}
		},
		error: function() {
						
		}
    });
})

var Form = $('#main-form');
Form.validate();
Form.on('submit',function() {
	try {
		if (Form.valid()) {

			if($('.hw-img-logo .list').length<1) {
				$.alert('请上传酒店logo！')
				return false;
			}
			if($('.hw-img-banner .list').length<1) {
				$.alert('请上传酒店品牌图！')
				return false;
			}
			if($('.hw-img-img .list').length<1) {
				$.alert('请上传封面图！')
				return false;
			}
			if($("#province option:selected").text()==''||$("#city option:selected").text()==""||$("#area option:selected").text()==""||$('.address_detail').val()=='') {
				$.alert('请填写地址！')
				return false;
			}
			if(ue.getContent()=='') {
				$.alert('请填写图文详情！')
				return false;
			}
			var reg = /^((0\d{2,3}-\d{7,8})|(1[37584]\d{9}))$/;

			console.log(reg.test($('input[name=phone]').val()));
 			if($('input[name=phone]').val()&&!reg.test($('input[name=phone]').val())){
				$.alert('请输入正确的联系电话');
				return false;
			}
			$.confirm({
				msg: '页面已修改，是否确认保存？',
				confirm: function(){
					Form.submitForm();
				}
			})
			
			// Form.submitForm();
		}
	} catch(e) {
		console.error(e);
	}

	return false;
});